#ifndef  __STREAM_H_
#define  __STREAM_H_

typedef unsigned int   uint;
typedef unsigned char  uint8;

// Output stream abstract class - used by the jpeg_encoder class to write to the output stream. 
// put_buf() is generally called with len==JPGE_OUT_BUF_SIZE bytes, but for headers it'll be called with smaller amounts.

struct memorystream
{

   uint8 *m_pBuf;
   uint m_buf_size, m_buf_ofs;

   memorystream(void *pBuf, uint buf_size){
	   m_pBuf = (static_cast<uint8*>(pBuf));
	   m_buf_size = buf_size;
	   m_buf_ofs = 0;
   }

   bool put_buf(const void* pBuf, int len){
	   uint buf_remaining = m_buf_size - m_buf_ofs;
	   if ((uint)len > buf_remaining)
		   return false;
	   memcpy(m_pBuf + m_buf_ofs, pBuf, len);
	   m_buf_ofs += len;
	   return true;
   }

   uint get_size() const{
	   return m_buf_ofs;
   }
};
	
#endif